home *** CD-ROM | disk | FTP | other *** search
- /* Born V2.1 © 1995 Echtelion. Coded by The Last Viking.
-
-
- This is a program that will remind you of various events. A typical
- use would be to insert it in the startup-sequence and put e.g. birthdays
- and other special days into the datafile.
-
- The package contains the following files.
-
- Born (The compiled Amiga code)
- Born.dta (Sample reminder file)
- Born.doc (Documentary)
- Born.c (The source-code. Should be ANSI-C Compatible)
-
- You can reach the author of this program on internet at:
- paalde@stud.cs.uit.no */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <time.h>
-
- FILE *fp;
- char ch,cha,chb;
- char *fname;
- int month,day=0;
-
- int drd,mrd,ard; /* dayread/monthread/advance warning */
- int dates[10][2];
- static int mtab[]={31,28,31,30,31,30,31,31,30,31,30,31};
-
- long li;
- struct tm *tp;
-
- void MError(int x);
- void calcnext10days(int d,int m);
- int leapy(int cy);
- int notify(int d,int m,int a);
- void header(void);
-
- void main(int argc, char *argv[]){
-
- time(&li); tp = localtime(&li);
- month=tp->tm_mon; day=tp->tm_mday;
-
- if (argc<2) {
- header();
- printf("Error 0: Parameter error, the following parameters are valid:\n\n");
- printf(" %s %s",argv[0],"filename silent\n");
- printf(" %s %s",argv[0],"filename\n");
- printf(" %s %s",argv[0],"help\n\n");
- printf("All the parameters must be written in lower-case.\n");
- exit (0);
- }
- fname=argv[1];
- if (!((strcmp(argv[1],"help")) && (strcmp(argv[1],"?")))) {
- printf("Welcome to Born 2.0.\n\n");
- printf("After 3 years of pure lazyness I managed to transfer the Modula-2 code into\n");
- printf("something more C'ish. I also came up with some new features for this program.\n");
- printf("Born is not a pure birthday reminder anymore, it's now usable for all sorts\n");
- printf("of reminding. You can also specify how many days in advance you want to be\n");
- printf("reminded of the particular event.\n\n");
- printf("The general syntax is:\n\n");
- printf(" %s %s",argv[0],"filename silent\n");
- printf(" %s %s",argv[0],"filename\n");
- printf(" %s %s",argv[0],"help\n\n");
- printf("All the parameters must be written in lower-case.\n\n");
- printf("If you have any serious problems with Born, then you might be able to reach\n");
- printf("me on Internet at: paalde@stud.cs.uit.no\n");
- exit (0);
- }
-
- if (((argc>=2) && (strcmp(argv[2],"silent")))) {header(); printf("\n");}
-
- if (leapy(tp->tm_year+1900)) {mtab[1]++;} /* shooting year */
- calcnext10days(day,month);
-
- if ((fp=fopen(fname,"r")) == NULL) MError(1); /* could not open file */
-
- /* 35 = # and 10 = lf's */
- while (ch=fgetc(fp)==35) {while (ch=fgetc(fp)!=10) {} }
-
- do {
- cha=fgetc(fp); chb=fgetc(fp); /* fetch day */
- if (cha!=88) {
- drd=10*(cha-48)+(chb-48);
- if ((cha<48) || (cha>58) || (chb<48) || (chb>58)) MError(6); /* range 0..9 */
-
- if (cha=fgetc(fp)!=45) MError(4);
-
- cha=fgetc(fp); chb=fgetc(fp); /* fetch month */
- if ((cha<48) || (cha>58) || (chb<48) || (chb>58)) MError(5);
- mrd=10*(cha-48)+(chb-48);
-
- if (cha=fgetc(fp)!=32) MError(7);
-
- cha=fgetc(fp);
- if ((cha<48) || (cha>58)) MError(8);
- ard=(cha-48);
- if (cha=fgetc(fp)!=32) MError(7);
-
- if (!(notify(drd,mrd,ard))) { /* was the date to be printed out? */
- if (drd<10) printf("0");
- printf("%d.",drd);
- if (mrd<10) printf("0");
- printf("%d.%d ",mrd,tp->tm_year);
- do {
- ch=getc(fp); printf("%c",ch);
- } while (ch!=10);
- }
- else { /* no! */
- do {
- ch=getc(fp);
- } while (ch!=10);
- } /* end printout */
- } /* if cha!=88 */
- } while (cha!=88); /* 88 = X */
-
- if (fclose(fp)) MError(2);
- }
-
- void header(void) {
- printf("Born V2.1 © 1992-95 Ecthelion. Time ");
- if (tp->tm_hour<10) printf("0"); /* write time information */
- printf("%d%s",tp->tm_hour,":");
- if (tp->tm_min<10) printf("0");
- printf("%d",tp->tm_min);
- printf(" Date "); /* write date information */
- if (day<10) printf("0");
- printf("%d.",day);
- if (month+1<10) printf("0");
- printf("%d.",month+1);
- printf("%d\n",tp->tm_year);
- }
-
- int notify(int d,int m,int a){
- int cnt=0;
- int found=1;
- do {
- if ((dates[cnt][0]==d) && (dates[cnt][1]==m)) {found=0;}
- cnt++;
- } while (cnt<a);
- return found;
- }
-
- void calcnext10days(int d,int m){
- int cnt=0;
- while (cnt<=9) {
- dates[cnt][0]=d; dates[cnt][1]=m+1;
- cnt++;
- d++;
- if (d>mtab[m]) {
- m++;d=1;
- if (m>11) m=0;
- }
- }
- }
-
- int leapy(int cy){
- return ((int) ((cy % 4 == 0) && ((cy % 100 >0) || (cy % 400 == 0))));
- }
-
- void MError(int x){
- if (x==1) printf("%s%s%s","Error 1: Can not open data-file: ",fname,".");
- if (x==2) printf("file close error.");
- if (x==3) printf("file read error.");
- if (x==4) printf("Error 4: Syntax error in datafile, missing - .");
- if (x==5) printf("Error 5: Syntax error in datafile, missing MONTH.");
- if (x==6) printf("Error 6: Syntax error in datafile, missing DAY.");
- if (x==7) printf("Error 7: Syntax error in datefile, missing ' '.");
- if (x==8) printf("Error 8: Syntax error in datefile, missing ADVANCE_DAYS.");
- printf("\n\n");
- exit(0);
- }
-
-